import java.util.Arrays;

public class Leetcode {
}
//leetcode:2418:按身高排序
class Solution1 {
    public String[] sortPeople(String[] names, int[] heights) {
        int n = heights.length;
        Integer[] ret = new Integer[n];
        for(int i = 0; i < n; i++){
            ret[i] = i;
        }

        //按身高对名字进行排序
        Arrays.sort(ret , (i, j) -> {
            return heights[j] - heights[i];
        });

        String[] s = new String[n];
        for(int i = 0; i < n; i++){
            s[i] = names[ret[i]];
        }

        return s;
    }
}

//leetcode:870:优势洗牌
class Solution2 {
    //田忌赛马
    public int[] advantageCount(int[] nums1, int[] nums2) {
        int n = nums1.length;
        //将数组1排序
        Arrays.sort(nums1);

        //记录下标
        Integer[] index = new Integer[n];
        for(int i = 0; i < n; i++){
            index[i] = i;
        }
        //让下标按照数组2进行排序
        Arrays.sort(index , (i,j) -> {
            return nums2[i]-nums2[j];
        });

        int left = 0 , right = n-1;
        int[] ret = new int[n];
        for(int i = 0; i < n; i++){
            //找到排序后的下标对应的数组2的值如果小于数组1
            if(nums1[i] <= nums2[index[left]]){
                //就让排序后最后下标对应的数组2的最大值位置的ret位置更新为nums1[i]
                ret[index[right--]] = nums1[i];
            }else{
                //大于就去更新对应的最小值位置
                ret[index[left++]] = nums1[i];
            }
        }
        return ret;
    }
}